package com.cxyd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxyd.domain.Stu;
import com.cxyd.mapper.StuMapper;
import com.cxyd.service.StuService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * @Author: huanglianyun
 * @Description:
 * @DATE: Created in 2020/2/4 16:28.
 */
@Service("stuService")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class StuServiceImpl extends ServiceImpl<StuMapper,Stu> implements StuService {

    @Autowired
    private StuMapper stuMapper;

    @Override
    public void addStu(Stu stu) {
        stuMapper.insert(stu);
    }

    @Override
    public IPage<Stu> selectPageStu(Page<Stu> page, String name, String teacher, String course) {
        QueryWrapper<Stu> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name),"name",name);
        queryWrapper.like(StringUtils.isNotBlank(teacher),"teacher",teacher);
        queryWrapper.like(StringUtils.isNotBlank(course),"course",course);
        IPage<Stu> stuIPage = this.page(page, queryWrapper);
        return stuIPage;
    }


}
